﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Windows.Forms;
using ChainAnalises.Classes.Root;
using ChainAnalises.Classes.TheoryOfSet;

namespace Segmentator.IntegrityThroughInterval
{
    class AlphabetComparer: DividerManager
    {
        private List<Dividers.Divider> dvd;
        private Alphabet _outAlpha;

        public AlphabetComparer()
        {
            dvd = new List<Dividers.Divider>();
          _outAlpha = new Alphabet();
        }

        public void Compare()
        {
            Dividers.Divider current_dvd;
            bool flag = false; // отсутствует
            IBaseObject msg1 = null, msg2 = null;
            current_dvd = dvdStack.Pop();
                for (int i = 0; i <= dvdStack.Count(); i++) dvd.Add(current_dvd);
       
            

            for (int k = 0; k < dvd[0].divided_chain.Alpahbet.power; k++)
            {
                msg1 = dvd[0].divided_chain.Alpahbet[k];

                for (int i = 1; i < dvd.Count(); i++)
                {
                    for (int j = 0; j < dvd[i].divided_chain.Alpahbet.power; j++)
                    {
                        msg2 = dvd[i].divided_chain.Alpahbet[j];
                        if (msg1.Equals(msg2))
                        {
                            flag = true;
                            break;
                        }
                        flag = false;
                    }
                    if (!flag) break;
                    
                }
                if (flag) _outAlpha.Add(msg1);
            }
        }


        public void Delete(int index)
        {
            
        }
        public Alphabet Get()
        {
            return _outAlpha;
        }

        private int GetSize()
        {
            return dvd.Count;
        }

        public List<string> toStringArray()
        {
            List<string> Alphabet = new List<string>();
            for (int i = 0; i < _outAlpha.power; i++)
            {
                Alphabet.Add(_outAlpha[i].ToString());
            }
            return Alphabet;
        }
    }
}
